@inherits MiniRazor.TemplateBase<CodeEntity>
@namespace OSharp.CodeGeneration.Templates
@using System;
@using System.Collections.Generic;
@using System.Linq;
@using OSharp.CodeGeneration.Services.Entities
@using OSharp.CodeGeneration.Utils
@using OSharp.Collections;
@using OSharp.Exceptions;
@using OSharp.Extensions;
@{
    CodeEntity entity = Model;
    string keyType = TypeHelper.ToSingleTypeName(entity.PrimaryKeyTypeFullName);
}// -----------------------------------------------------------------------
// <auto-generated>
//    此代码由代码生成器生成。
//    手动更改此文件可能导致应用程序出现意外的行为。
//    如果重新生成代码，对此文件的任何修改都会丢失。
//    如果需要扩展此类，可以遵守如下规则进行扩展：
//      1.横向扩展：如需给当前控制器添加API，请在控制器类型 @(entity.Name)Controller.cs 进行添加
//      2.纵向扩展：如需要重写当前控制器的API实现，请在控制器类型 @(entity.Name)Controller.cs 进行继承重写
// </auto-generated>
//
// <copyright file="@(entity.Name)Base.generated.cs" company="@entity.Module.Project.Company">
//    @entity.Module.Project.Copyright
// </copyright>
// <site>@entity.Module.Project.SiteUrl</site>
// <last-editor>@entity.Module.Project.Creator</last-editor>
// -----------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;

using OSharp.AspNetCore.Mvc;
using OSharp.AspNetCore.Mvc.Filters;
using OSharp.AspNetCore.UI;
using OSharp.Caching;
using OSharp.Authorization.Functions;
using OSharp.Authorization.Modules;
using OSharp.Data;
using OSharp.Entity;
using OSharp.Filter;
using OSharp.Security;

using @(entity.Module.Namespace);
using @(entity.Module.Namespace).Dtos;
using @(entity.Module.Namespace).Entities;


namespace @(entity.Module.Project.NamespacePrefix).Web.Areas.Admin.Controllers
{
    /// <summary>
    /// 管理控制器基类: @(entity.Display)信息
    /// </summary>
    [ModuleInfo(Position = "@(entity.Module.Name)", PositionName = "@(entity.Module.Display)模块")]
    [Description("管理-@(entity.Display)信息")]
    public abstract class @(entity.Name)ControllerBase : AdminApiControllerBase
    {
        private readonly IServiceProvider _provider;

        /// &lt;summary&gt;
        /// 初始化一个&lt;see cref="@(entity.Name)Controller"/&gt;类型的新实例
        /// &lt;/summary&gt;
        protected @(entity.Name)ControllerBase(IServiceProvider provider)
            : base(provider)
        {
            _provider = provider;
        }

        /// <summary>
        /// 获取或设置 @(entity.Module.Display)模块业务契约对象
        /// </summary>
        protected I@(entity.Module.Name)Contract @(entity.Module.Name)Contract => _provider.GetRequiredService&lt;I@(entity.Module.Name)Contract&gt;();
@if (entity.Listable)
{
        <text>
        /// &lt;summary&gt;
        /// 读取@(entity.Display)列表信息
        /// &lt;/summary&gt;
        /// &lt;param name="request"&gt;页请求信息&lt;/param&gt;
        /// &lt;returns&gt;JSON操作结果&lt;/returns&gt;
        [HttpPost]
        [ModuleInfo]
        [Description("读取")]
        public virtual AjaxResult Read(PageRequest request)
        {
            Check.NotNull(request, nameof(request));

            Expression&lt;Func&lt;@(entity.Name), bool&gt;&gt; predicate = FilterService.GetExpression&lt;@(entity.Name)&gt;(request.FilterGroup);
            var page = @(entity.Module.Name)Contract.@(entity.Name.ToPlural()).ToPage&lt;@(entity.Name), @(entity.Name)OutputDto&gt;(predicate, request.PageCondition);

            return new AjaxResult("success", AjaxResultType.Success, page.ToPageData());
        }
</text>
}
@if (entity.Addable)
{
        <text>
        /// &lt;summary&gt;
        /// 新增@(entity.Display)信息
        /// &lt;/summary&gt;
        /// &lt;param name="dtos"&gt;@(entity.Display)信息输入DTO&lt;/param&gt;
        /// &lt;returns&gt;JSON操作结果&lt;/returns&gt;
        [HttpPost]
        [ModuleInfo]
        [DependOnFunction(nameof(Read))]
        [UnitOfWork]
        [Description("新增")]
        public virtual async Task&lt;AjaxResult&gt; Create(@(entity.Name)InputDto[] dtos)
        {
            Check.NotNull(dtos, nameof(dtos));
            OperationResult result = await @(entity.Module.Name)Contract.Create@(entity.Name.ToPlural())(dtos);
            return result.ToAjaxResult();
        }
</text>
}
@if (entity.Updatable)
{
        <text>
        /// &lt;summary&gt;
        /// 更新@(entity.Display)信息
        /// &lt;/summary&gt;
        /// &lt;param name="dtos"&gt;@(entity.Display)信息输入DTO&lt;/param&gt;
        /// &lt;returns&gt;JSON操作结果&lt;/returns&gt;
        [HttpPost]
        [ModuleInfo]
        [DependOnFunction(nameof(Read))]
        [UnitOfWork]
        [Description("更新")]
        public virtual async Task&lt;AjaxResult&gt; Update(@(entity.Name)InputDto[] dtos)
        {
            Check.NotNull(dtos, nameof(dtos));
            OperationResult result = await @(entity.Module.Name)Contract.Update@(entity.Name.ToPlural())(dtos);
            return result.ToAjaxResult();
        }
</text>
}
@if (entity.Deletable)
{
        <text>
        /// &lt;summary&gt;
        /// 删除@(entity.Display)信息
        /// &lt;/summary&gt;
        /// &lt;param name="ids"&gt;@(entity.Display)信息编号&lt;/param&gt;
        /// &lt;returns&gt;JSON操作结果&lt;/returns&gt;
        [HttpPost]
        [ModuleInfo]
        [DependOnFunction(nameof(Read))]
        [UnitOfWork]
        [Description("删除")]
        public virtual async Task&lt;AjaxResult&gt; Delete(@(keyType)[] ids)
        {
            Check.NotNull(ids, nameof(ids));
            OperationResult result = await @(entity.Module.Name)Contract.Delete@(entity.Name.ToPlural())(ids);
            return result.ToAjaxResult();
        }
</text>
}
    }
}
